home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / LFLTS / LATNRM.HLP < prev    next >
Text File  |  1989-01-24  |  8KB  |  165 lines

  1.          Name: LATNRM.ASM
  2.          Type: Assembler Macro
  3.       Version: 1.0
  4.   Last Change:  1-Aug-86
  5.  
  6.  Description: Normalized Lattice IIR Filter Assembler Macro
  7.  
  8.  This implements a normalized lattice filter as described by
  9.  A. Gray and J. Markel in "A Normalized Digital Filter Structure",
  10.  IEEE ASSP June, 1975.
  11.  
  12.  
  13.  
  14.  
  15.  
  16.    | input
  17.    V
  18.    ------q2---->(+)-------->-----q1---->(+)-------->-----q0-->(+)---------
  19.     |            ^          |            ^          |          ^         |
  20.     |            |          |            |          |          |         |
  21.     k2          -k2         k1          -k1         k0        -k0        V
  22.     |            |          |            |          |          |         |
  23.     V            |          V            |          V          |         |
  24.   -(+)<--q2-------<--1/z---(+)<---q1------<--1/z---(+)<--q0-----<--1/z----
  25.   |                s2    |                 s1    |               s0    |
  26.   v3                     v2                      v1                    v0
  27.   |                       \_______    __________/                      |
  28.    \                              \  /                                /
  29.      ------------------------------(+)--------------------------------
  30.                                     L_________> output
  31.  
  32.  
  33.  output sample is in A.  The filter is called by:
  34.  
  35.      latnrm      order          ;call normalized lattice filter
  36.  
  37.  where 'latnrm' is the filter macro name and 'order' is the order
  38.  (number of different k parameters) of the filter (3 in this example).
  39.  An example of how to use this macro is found in the DSPLIB in the
  40.  file LATNRMT.ASM.
  41.  
  42.   The address registers are set as:
  43.  
  44.         r0                                  r4
  45.         |                                   | 
  46.         v                                   v
  47.      X: q2 k2 q1 k1 q0 k0 v3 v2 v1 v0    Y: sx s2 s1 s0
  48.  
  49.         m0=3*N (=9, mod 10)                 m4=N  (=3, mod 4)
  50.  
  51.  
  52.   The register R0  is  initialized  to  point  to  the  first  q
  53.   coefficient  of  the  leftmost  section  of  the  filter.  The
  54.   register R4 is initialized to point to the first  location  of
  55.   modulo  storage for the filter states.  The modulo register M0
  56.   is initialized to three times the order of  the  filter.   The
  57.   modulo  register  M4 is initialized to the order of the filter
  58.   (note that this results in a modulus of ORDER+1).
  59.  
  60.   The input sample is put in y0 (called w in the  comments)  and
  61.   the output sample is in A.  The filter is called by:
  62.  
  63.        latnrm      order    ;call normalized lattice filter
  64.  
  65.   where 'latnrm' is the filter macro name and  'order'  is  the
  66.   order  (number  of different k parameters) of the filter (3 in
  67.   this example).
  68.  
  69.   FILTER OPERATION
  70.  
  71.   The operation of this filter can be described (refer to Figure
  72.   7 and the macro 'latnrm'):
  73.  
  74.   1.  The input sample is initially in product register Y0.  The
  75.       pointer  R0  is  initially  pointing  to  the first filter
  76.       coefficient (Q2) and the state pointer R4 is  pointing  to
  77.       the first location of the state variable storage.
  78.  
  79.   2.  The first MOVE instruction loads the first  Q  coefficient
  80.       into  X1  for  the  leftmost  section  of the filter.  The
  81.       pointer R0 is  then  incremented  to  point  to  the  next
  82.       coefficient  (K).   Each  section  of  the filter has four
  83.       multiplies with an additional multiply after the  loop  to
  84.       compute the FIR taps.  Each section of this filter has the
  85.       appearance of a "box".
  86.  
  87.   3.  The loop then makes ORDER passes.   This  loop  calculates
  88.       the  state  variables.   These  state  variables are later
  89.       multiplied by the V coefficient taps and  summed  to  form
  90.       the output.
  91.  
  92.   4.  The first multiply in the loop multiplies the  input  (Y0)
  93.       by  the first coefficient (Q2 in X1) and leaves the result
  94.       in A.  This computes the top of the box.   Simultaneously,
  95.       the  k  coefficient (k2) for this section of the filter is
  96.       loaded and the coefficient pointer  is  incremented.   The
  97.       state  variable  for  this  section  of the filter is also
  98.       loaded (Y1) and the pointer to the state variables is  not
  99.       incremented  so  that  later  in  the  loop, the new state
  100.       variable can be written in its place.
  101.  
  102.   5.  The second instruction of the loop (MAC) multiplies the  k
  103.       coefficient  (in  X0)  by  the  state  variable previously
  104.       loaded (Y1) and subtracts this  result  from  the  summing
  105.       junction  at  the top right of the box.  This value is the
  106.       top left input to the next section  of  the  filter.   The
  107.       value  in  B  is  saved  as the new state variable and the
  108.       pointer R4 is incremented  to  point  to  the  next  state
  109.       variable.   Note  that  on the first pass of the loop, the
  110.       value in B is unknown and an unknown value is saved as the
  111.       first   state   variable.    This   value   is  eventually
  112.       overwritten after exiting the loop.
  113.  
  114.   6.  The next multiply will multiply the input  value  (Y0)  by
  115.       the k coefficient (X0) to compute the left side of the box
  116.       (B).  At this point, the top right value of the box (A) is
  117.       moved into a product register (Y0) to be used as the input
  118.       to the next filter section.
  119.  
  120.   7.  The state variable at the bottom left of the box  is  then
  121.       computed  by  summing  the value from the left side of the
  122.       box (B) with the product of the q value (Q2 in X1) and the
  123.       state  variable  (Y1).   This  resulting state variable is
  124.       saved on the next pass of the loop.  The next q value  for
  125.       the  next section of the filter is then loaded into X1 and
  126.       the pointer R0 is incremented.
  127.  
  128.   8.  Upon exiting from the loop, the loop  has  calculated  and
  129.       saved  ORDER-1  state variables (the first value saved was
  130.       an unknown value do to the order of the statements  always
  131.       saving  the last state variable and upon entry to the loop
  132.       the last  state  variable  is  a  unknown  value).   Since
  133.       ORDER+1  state  variables  are  needed  to compute the FIR
  134.       taps, the other two state variables need to be saved yet.
  135.  
  136.   9.  The value in the last state is then rounded and the second
  137.       last  state  is  saved (B).  The pointer is incremented to
  138.       point to the next  state  position.   At  this  point  the
  139.       pointer  is  pointing  to the unknown value that was first
  140.       written.
  141.  
  142.   10. The top rightmost value (in A) is then saved as  the  last
  143.       state.   This value overwrites the unknown value initially
  144.       saved.  The pointer R4 increments to point  to  the  state
  145.       value to multiply the tap v3.
  146.  
  147.  11.  The state variable to multiply V3 by is then  loaded  into
  148.       Y0  and  the  A  register is cleared to accumulate the FIR
  149.       taps.
  150.  
  151.  12.  A repeat instruction is used to  multiply  and  accumulate
  152.       ORDER  taps.   The  last  pass  of the DO loop had already
  153.       loaded the first v coefficient (V3) into X1.
  154.  
  155.  13.  The last FIR tap is then multiplied, accumulated  and  the
  156.       result  is  rounded.  Since R4 was incremented once before
  157.       the repeat loop and ORDER times during the loop, R4 now is
  158.       pointing  to  the same position again (the modulo on R4 is
  159.       ORDER+1).  The register R4 is then incremented to point to
  160.       the  next  state which is the first state to be loaded for
  161.       the next sample time.
  162.  
  163.  Benchmarks for this filter are:
  164.  13 instructions, 5N+9 instructions cycles, 2 stack locations.
  165.